import Vue from 'vue'
import App from './App'

import VueCompositionAPI from '@vue/composition-api'
Vue.use(VueCompositionAPI)

// import './common/common.css'
import {
	TimeFormat
} from 'common/timeFormat.js'
//uview
import uView from "uview-ui";
Vue.use(uView);
// 定义全局方法
import {
	countDown,
	formatTime,
	getQueryString,
	jinwei
} from "./common/common.js";
// import "./style.less";


import GoEasy from '@/uni_modules/GOEASY-IM/js_sdk/goeasy-2.13.13.esm.min.js'
import GRTC from './lib/goeasy-rtc-0.3.6.esm.min.js'

GoEasy.init({
	host: 'hangzhou.goeasy.io', //应用所在的区域地址: 【hangzhou.goeasy.io |singapore.goeasy.io】
	appkey: 'BC-7556eed682b94964ac91164a9a7583a5', // common key,
	modules: ['im'],
	allowNotification: true //仅有效于app,小程序和H5将会被自动忽略
});
GRTC.init(GoEasy);
uni.$GoEasy = GoEasy;
uni.$GRTC = GRTC;
GoEasy.onClickNotification((message) => {
	// debugger
    let currentUrl;
    const routes = getCurrentPages();

    if (routes && routes.length) {
        const curRoute = routes[routes.length - 1].route;
        const curParam = routes[routes.length - 1].options;
        currentUrl = '/' + curRoute + `?to=${curParam.to}`;
    }

    let newUrl;
    switch (message.toType) {
        case GoEasy.IM_SCENE.PRIVATE:
            newUrl = '/pages/privateChat?to=' + message.senderId;
            break;
        case GoEasy.IM_SCENE.GROUP:
            newUrl = '/pages/groupChat?to=' + message.groupId;
            break;
    }

    if (currentUrl !== newUrl) {
        uni.navigateTo({
            url: newUrl,
        });
    }

});

// 挂载全局方法

Vue.prototype.jinwei = jinwei
Vue.prototype.countDown = countDown
Vue.prototype.formatTime = formatTime
Vue.prototype.getQueryString = getQueryString
Vue.prototype.GoBack = () => {
	console.log('GoBack执行返回')
	const pages = getCurrentPages()
	const route = pages[pages.length - 1]['$page']['fullPath']
	if (pages.length == 1 || route == '/pages/market/index') {
		console.log('执行到了')
		uni.switchTab({
			url: '/pages/goodsIndex/index'
		});
		return
	}
	uni.navigateBack({
		delta: 1,
		success: function() {
			console.log('成功返回到上一个页面');
		},
		fail: function() {
			console.log('返回失败');
		}
	})
}
Vue.config.productionTip = false
Vue.prototype.$TimeFormat = TimeFormat

App.mpType = 'app'

const app = new Vue({
	...App,
})
app.$mount()